import java.util.ArrayList;

public class Exercise15_03{
    public static void main(String[] args){
        ArrayList<Point> pointArr = new ArrayList<Point>();
        
        for(int i = 0; i < 5; i++){
            int x = (int)(Math.random()*20);
            int y = (int)(Math.random()*20);
            Point p = new Point(x, y);
            pointArr.add(p);
        }
        
        System.out.println("按x升序:");
        for(int i = 0; i < pointArr.size() - 1; i++){
            for(int j = i + 1; j < pointArr.size(); j++){
                if(pointArr.get(i).x > pointArr.get(j).x){
                    int temp = pointArr.get(i).x;
                    pointArr.get(i).x = pointArr.get(j).x;
                    pointArr.get(j).x = temp;
                }
            }
        }
        showArrList(pointArr);
        
        System.out.println("按y升序:");
        for(int i = 0; i < pointArr.size() - 1; i++){
            for(int j = i + 1; j < pointArr.size(); j++){
                if(pointArr.get(i).y > pointArr.get(j).y){
                    int temp = pointArr.get(i).y;
                    pointArr.get(i).y = pointArr.get(j).y;
                    pointArr.get(j).y = temp;
                }
            }
        }
        showArrList(pointArr);        
        
        System.out.println("按距离升序:");
        for(int i = 0; i < pointArr.size() - 1; i++){
            for(int j = i + 1; j < pointArr.size(); j++){
                if(pointArr.get(i).len > pointArr.get(j).len){
                    double temp = pointArr.get(i).len;
                    pointArr.get(i).len = pointArr.get(j).len;
                    pointArr.get(j).len = temp;
                }
            }
        }
        showArrList(pointArr);        
    }
    
    public static void showArrList(ArrayList<Point> ap){
        for(int i = 0; i < ap.size(); i++){
            ap.get(i).show();
        }
    }
}

class Point{
    int x;
    int y;
    double len;
    
    public Point(int x, int y){
        this.x = x;
        this.y = y;
        this.len = Math.sqrt(x*x + y*y);    
    }
    public void show(){
        System.out.println("x: " + x);
        System.out.println("y: " + y);
        System.out.println("len: " + len);
    }
}